class Solution {
public:
    void result(TreeNode* root, set<int> & save)
    {
        if(root==nullptr)
            return ;

        auto  ret =save.find(root->val);
        if(ret==save.end())
        {
            save.insert(root->val);
        }
        result(root->left,save);
        result(root->right,save);
    }
    int numColor(TreeNode* root)
    {
        set<int> save;

        result(root,save);

        return save.size();
    }
};
